import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'bottomTabs/Home.dart';
import 'bottomTabs/Setting.dart';
import 'bottomTabs/Category.dart';

// 首页底部导航栏
class HomeBottomTabs extends StatefulWidget {
  final index;
  HomeBottomTabs({this.index = 0});

  @override
  State<StatefulWidget> createState() => HomeBottomTabsState(this.index);
}

class HomeBottomTabsState extends State {
  int _currentIndex;
  List _pageList = [
    HomePage(),
    CategoryPage(),
    SettingPage(),
  ];
  List _titleList = ['Home', 'Category', 'Setting'];

  HomeBottomTabsState(index) {
    this._currentIndex = index;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _currentIndex == 1 ? null : AppBar(title: Text(_titleList[_currentIndex])),
      body: _pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _currentIndex,
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.category,color: Colors.white), label: '分类'),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
          ],
          onTap: (index) {
            setState(() {
              _currentIndex = index;
            });
          }),
      drawer: _currentIndex == 1 ? null : Drawer(
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: DrawerHeader(
                    child: Text('左侧drawer'),
                    decoration: BoxDecoration(
//                        color: Colors.yellow,
                        image: DecorationImage(
                          image: AssetImage('images/2.png'),
                          fit: BoxFit.cover,
                        )),
                  ),
                ),
              ],
            ),
            ListTile(
              leading: Icon(Icons.search, color: Colors.red),
              title: Text('登录'),
              onTap: () {
                Navigator.of(context).pop(); // 隐藏侧边栏
                Navigator.pushNamed(context, '/login');
              },
            ),
            Divider(height: 1),
            ListTile(
                leading: Icon(Icons.home, color: Colors.red),
                title: Text('左侧侧边栏')),
            Divider(height: 1),
            ListTile(
                leading: Icon(Icons.home, color: Colors.red),
                title: Text('左侧侧边栏')),
            Divider(height: 1),
          ],
        ),
      ),
      endDrawer: _currentIndex == 1 ? null : Drawer(
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: UserAccountsDrawerHeader(
                      accountName: Text('大地老师'),
                      accountEmail: Text('dadi@qq.com'),
                      currentAccountPicture: CircleAvatar(
                        backgroundImage: AssetImage('images/2.png'),
                      ),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage('images/2.png'),
                          fit: BoxFit.cover,
                        ),
                      )),
                ),
              ],
            ),
            ListTile(
                leading: Icon(Icons.home, color: Colors.red),
                title: Text('左侧侧边栏')),
            Divider(height: 1),
            ListTile(
                leading: Icon(Icons.home, color: Colors.red),
                title: Text('左侧侧边栏')),
            Divider(height: 1),
            ListTile(
                leading: Icon(Icons.home, color: Colors.red),
                title: Text('左侧侧边栏')),
            Divider(height: 1),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add,size: 40.0),
        onPressed: () {
          print('FloatingActionButton');
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
